#include "tcpci_timer.h"
#include "tcpci_event.h"
#include "tcpci.h"
#include "tcpci_core.h"
#include "MultiTimer.h"

#undef LOG_TAG
#define LOG_TAG    "tcpc_timer"
#include "elog.h"

#define RT_MASK64(i)			(((uint64_t)1) << i)
#define TIMEOUT_VAL(val)		((val) * 1000)
#define TIMEOUT_RANGE(min, max)		(((min) + (max)) * 1000 / 2)
//#define TIMEOUT_RANGE(min, max)		(((min) * 3 + (max) * 2) * 1000 / 5)

MultiTimer pd_timer[PD_TIMER_NR];

//add for bist mode
MultiTimer bist_mode;

struct tcpc_timer_desc {
#if TYPEC_TIMER_INFO
    const char *const name;
#endif // TYPEC_TIMER_INFO
    const uint32_t tout;
};

#if TYPEC_TIMER_INFO
#define DECL_TCPC_TIMEOUT_RANGE(name, min, max) { #name, \
						  TIMEOUT_RANGE(min, max) }
#define DECL_TCPC_TIMEOUT(name, ms)		{ #name, TIMEOUT_VAL(ms) }
#else
#define DECL_TCPC_TIMEOUT_RANGE(name, min, max)	{ TIMEOUT_RANGE(min, max) }
#define DECL_TCPC_TIMEOUT(name, ms)		{ TIMEOUT_VAL(ms) }
#endif

#define PD_TIMER_SENDER_RESPONSE_TIMEOUT_20 TIMEOUT_VAL(24)
#define PD_TIMER_SENDER_RESPONSE_TIMEOUT_30 TIMEOUT_VAL(29)

const struct tcpc_timer_desc tcpc_timer_desc[PD_TIMER_NR] = {
#if 1
DECL_TCPC_TIMEOUT_RANGE(PD_TIMER_DISCOVER_ID, 40, 50),
DECL_TCPC_TIMEOUT_RANGE(PD_TIMER_BIST_CONT_MODE, 30, 60),
DECL_TCPC_TIMEOUT_RANGE(PD_TIMER_NO_RESPONSE, 4500, 5500),
DECL_TCPC_TIMEOUT_RANGE(PD_TIMER_PS_HARD_RESET, 25, 35),
DECL_TCPC_TIMEOUT_RANGE(PD_TIMER_PS_SOURCE_OFF, 750, 920),
DECL_TCPC_TIMEOUT_RANGE(PD_TIMER_PS_SOURCE_ON, 390, 480), //comon.check5
DECL_TCPC_TIMEOUT_RANGE(PD_TIMER_PS_TRANSITION, 450, 550),
DECL_TCPC_TIMEOUT_RANGE(PD_TIMER_SENDER_RESPONSE, 27, 33), //to do
DECL_TCPC_TIMEOUT(PD_TIMER_SINK_REQUEST, 150), // at least 100ms
DECL_TCPC_TIMEOUT_RANGE(PD_TIMER_SINK_WAIT_CAP, 310, 620),
DECL_TCPC_TIMEOUT_RANGE(PD_TIMER_SOURCE_CAPABILITY, 100, 200),
DECL_TCPC_TIMEOUT(PD_TIMER_SOURCE_START, 30), // at least 20ms
DECL_TCPC_TIMEOUT(PD_TIMER_VCONN_ON, 100),
#if CONFIG_USB_PD_VCONN_STABLE_DELAY
DECL_TCPC_TIMEOUT(PD_TIMER_VCONN_STABLE, 50),
#endif	/* CONFIG_USB_PD_VCONN_STABLE_DELAY */
DECL_TCPC_TIMEOUT_RANGE(PD_TIMER_VDM_MODE_ENTRY, 40, 50),
DECL_TCPC_TIMEOUT_RANGE(PD_TIMER_VDM_MODE_EXIT, 40, 50),
DECL_TCPC_TIMEOUT_RANGE(PD_TIMER_VDM_RESPONSE, 24, 30),
DECL_TCPC_TIMEOUT_RANGE(PD_TIMER_SOURCE_TRANSITION, 25, 35),
DECL_TCPC_TIMEOUT(PD_TIMER_SOURCE_SWAP_STANDBY, 650),
DECL_TCPC_TIMEOUT(PD_TIMER_SRC_RECOVER, 900 - CONFIG_USB_PD_SAFE0V_DELAY),
#if CONFIG_USB_PD_REV30
DECL_TCPC_TIMEOUT(PD_TIMER_CK_NOT_SUPPORTED, 40),
DECL_TCPC_TIMEOUT_RANGE(PD_TIMER_SINK_TX, 16, 20),
#if CONFIG_USB_PD_REV30_PPS_SOURCE
DECL_TCPC_TIMEOUT_RANGE(PD_TIMER_SOURCE_PPS_TIMEOUT, 12000, 15000),
#endif	/* CONFIG_USB_PD_REV30_PPS_SOURCE */
#endif	/* CONFIG_USB_PD_REV30 */
/* tPSHardReset + tSafe0V = 35 + 650 */
DECL_TCPC_TIMEOUT(PD_TIMER_HARD_RESET_SAFE0V, 685),
/* tSrcRecover + tSrcTurnOn = 1000 + 275 */
DECL_TCPC_TIMEOUT(PD_TIMER_HARD_RESET_SAFE5V, 1275),

/* PD_TIMER (out of spec) */
#if CONFIG_USB_PD_SAFE0V_DELAY
DECL_TCPC_TIMEOUT(PD_TIMER_VSAFE0V_DELAY, CONFIG_USB_PD_SAFE0V_DELAY),
#endif	/* CONFIG_USB_PD_SAFE0V_DELAY */
#if CONFIG_USB_PD_SAFE0V_TIMEOUT
DECL_TCPC_TIMEOUT(PD_TIMER_VSAFE0V_TOUT, CONFIG_USB_PD_SAFE0V_TIMEOUT),
#endif	/* CONFIG_USB_PD_SAFE0V_TIMEOUT */
#if CONFIG_USB_PD_SAFE5V_DELAY
DECL_TCPC_TIMEOUT(PD_TIMER_VSAFE5V_DELAY, CONFIG_USB_PD_SAFE5V_DELAY),
#endif	/* CONFIG_USB_PD_SAFE5V_DELAY */
#if CONFIG_USB_PD_RETRY_CRC_DISCARD
DECL_TCPC_TIMEOUT(PD_TIMER_DISCARD, 3),
#endif	/* CONFIG_USB_PD_RETRY_CRC_DISCARD */
#if CONFIG_USB_PD_VBUS_STABLE_TOUT
DECL_TCPC_TIMEOUT(PD_TIMER_VBUS_STABLE, CONFIG_USB_PD_VBUS_STABLE_TOUT),
#endif	/* CONFIG_USB_PD_VBUS_STABLE_TOUT */
DECL_TCPC_TIMEOUT(PD_TIMER_CVDM_RESPONSE, CONFIG_USB_PD_CUSTOM_VDM_TOUT),
DECL_TCPC_TIMEOUT(PD_TIMER_DFP_FLOW_DELAY, CONFIG_USB_PD_DFP_FLOW_DLY),
DECL_TCPC_TIMEOUT(PD_TIMER_UFP_FLOW_DELAY, CONFIG_USB_PD_UFP_FLOW_DLY),
DECL_TCPC_TIMEOUT(PD_TIMER_VCONN_READY, CONFIG_USB_PD_VCONN_READY_TOUT),
DECL_TCPC_TIMEOUT(PD_PE_VDM_POSTPONE, 3),
#if CONFIG_USB_PD_REV30
DECL_TCPC_TIMEOUT(PD_TIMER_DEFERRED_EVT, 5000),
#if CONFIG_USB_PD_REV30_SNK_FLOW_DELAY_STARTUP
DECL_TCPC_TIMEOUT(PD_TIMER_SNK_FLOW_DELAY, CONFIG_USB_PD_UFP_FLOW_DLY),
#endif	/* CONFIG_USB_PD_REV30_SNK_FLOW_DELAY_STARTUP */
#if CONFIG_USB_PD_REV30_PPS_SINK
DECL_TCPC_TIMEOUT(PD_TIMER_PPS_REQUEST, CONFIG_USB_PD_PPS_REQUEST_INTERVAL),
#endif	/* CONFIG_USB_PD_REV30_PPS_SINK */
#endif	/* CONFIG_USB_PD_REV30 */
DECL_TCPC_TIMEOUT(PD_TIMER_PE_IDLE_TOUT, 10),
#endif /* CONFIG_USB_POWER_DELIVERY */

/* TYPEC_RT_TIMER (out of spec) */
DECL_TCPC_TIMEOUT(TYPEC_RT_TIMER_SAFE0V_DELAY, 35),
DECL_TCPC_TIMEOUT(TYPEC_RT_TIMER_SAFE0V_TOUT, 650),
DECL_TCPC_TIMEOUT(TYPEC_RT_TIMER_ROLE_SWAP_START, 20),
DECL_TCPC_TIMEOUT(TYPEC_RT_TIMER_ROLE_SWAP_STOP, CONFIG_TYPEC_CAP_ROLE_SWAP_TOUT),
DECL_TCPC_TIMEOUT(TYPEC_RT_TIMER_STATE_CHANGE, 50),
DECL_TCPC_TIMEOUT(TYPEC_RT_TIMER_DISCHARGE, CONFIG_TYPEC_CAP_DISCHARGE_TOUT),
DECL_TCPC_TIMEOUT(TYPEC_RT_TIMER_LOW_POWER_MODE, 1000),
#if 1
DECL_TCPC_TIMEOUT(TYPEC_RT_TIMER_PE_IDLE, 1),
#if CONFIG_USB_PD_WAIT_BC12
DECL_TCPC_TIMEOUT(TYPEC_RT_TIMER_PD_WAIT_BC12, 50),
#endif /* CONFIG_USB_PD_WAIT_BC12 */
#endif	/* CONFIG_USB_POWER_DELIVERY */
#if CONFIG_WATER_DETECTION
DECL_TCPC_TIMEOUT(TYPEC_RT_TIMER_WD_IN_KPOC, 1000),
#endif /* CONFIG_WATER_DETECTION */
DECL_TCPC_TIMEOUT_RANGE(TYPEC_TIMER_ERROR_RECOVERY, 25, 25),

/* TYPEC_TRY_TIMER */
DECL_TCPC_TIMEOUT_RANGE(TYPEC_TRY_TIMER_DRP_TRY, 75, 150),
/* TYPEC_DEBOUNCE_TIMER */
DECL_TCPC_TIMEOUT_RANGE(TYPEC_TIMER_CCDEBOUNCE, 100, 200),
DECL_TCPC_TIMEOUT_RANGE(TYPEC_TIMER_PDDEBOUNCE, 10, 20),
DECL_TCPC_TIMEOUT_RANGE(TYPEC_TIMER_TRYCCDEBOUNCE, 10, 20),
DECL_TCPC_TIMEOUT_RANGE(TYPEC_TIMER_SRCDISCONNECT, 0, 20),  // shall detect SRC.Open as quickly as possible
DECL_TCPC_TIMEOUT_RANGE(TYPEC_TIMER_DRP_SRC_TOGGLE, 50, 100),

/* TYPEC_TIMER (out of spec) */
#if CONFIG_TYPEC_CAP_NORP_SRC
DECL_TCPC_TIMEOUT(TYPEC_TIMER_NORP_SRC, 300),
#endif	/* CONFIG_TYPEC_CAP_NORP_SRC */
};

extern volatile uint32_t g_sys_ticks;

struct call_data{
    uint8_t id;
#if TYPEC_TIMER_INFO
    char name[32];
#endif
	uint32_t tout;
};

struct call_data timer_call_data[PD_TIMER_NR] = {0};


struct call_data_bist_mode{
	uint8_t id;
	uint8_t enable;
	char name[32];
	uint32_t tout;
	
};
struct call_data_bist_mode bist_call_data = {0};

inline uint32_t millis (void)
{
   return g_sys_ticks;
}

uint32_t getPlatformTicks()
{
    return millis();
}

/*
void timerCallback1(MultiTimer* timer, void* userData) {
	int cnt  = ((struct tcpc_timer_desc *)(timer->userData))->tout;
#if TYPEC_TIMER_INFO
    log_i("name = %s ,time =%d\r\n",((struct tcpc_timer_desc *)(timer->userData))->name,cnt);
#endif
    multiTimerStart(timer, cnt/1000, timerCallback1, userData); // Restart timer
}
*/

#if 1
void on_pe_timer_timeout(
		struct sgm41620_tcpc *tcpc, uint32_t timer_id)
{
	struct pd_event pd_event = {0};
	int ret = 0;

	pd_event.event_type = PD_EVT_TIMER_MSG;
	pd_event.msg = timer_id;
	pd_event.pd_msg = NULL;

	switch (timer_id) {
	case PD_TIMER_VDM_MODE_ENTRY:
	case PD_TIMER_VDM_MODE_EXIT:
	case PD_TIMER_VDM_RESPONSE:
	case PD_TIMER_CVDM_RESPONSE:
		pd_put_vdm_event(tcpc, &pd_event, false);
		break;

#if CONFIG_USB_PD_SAFE0V_DELAY
	case PD_TIMER_VSAFE0V_DELAY:
		pd_put_vbus_safe0v_event(tcpc, true);
		break;
#endif	/* CONFIG_USB_PD_SAFE0V_DELAY */

#if CONFIG_USB_PD_SAFE0V_TIMEOUT
	case PD_TIMER_VSAFE0V_TOUT:
		log_i("VSafe0V TOUT (%d)\n", tcpc->vbus_level);
		ret = tcpci_check_vbus_valid_from_ic(tcpc);
		pd_put_vbus_safe0v_event(tcpc, !ret);
		break;
#endif	/* CONFIG_USB_PD_SAFE0V_TIMEOUT */

#if CONFIG_USB_PD_SAFE5V_DELAY
	case PD_TIMER_VSAFE5V_DELAY:
		pd_put_vbus_changed_event(tcpc);
		break;
#endif	/* CONFIG_USB_PD_SAFE5V_DELAY */

#if CONFIG_USB_PD_RETRY_CRC_DISCARD
	case PD_TIMER_DISCARD:
		if (!tcpc->pd_discard_pending) {
			break;
		}
		tcpc->pd_discard_pending = false;
		pd_put_hw_event(tcpc, PD_HW_TX_DISCARD);
		break;
#endif	/* CONFIG_USB_PD_RETRY_CRC_DISCARD */

#if CONFIG_USB_PD_VBUS_STABLE_TOUT
	case PD_TIMER_VBUS_STABLE:
		pd_put_vbus_stable_event(tcpc);
		break;
#endif	/* CONFIG_USB_PD_VBUS_STABLE_TOUT */

	case PD_PE_VDM_POSTPONE:
		pd_postpone_vdm_event_timeout(tcpc);
		break;

	case PD_TIMER_PE_IDLE_TOUT:
		log_i("pe_idle tout\n");
		pd_put_pe_event(p_pd_port, PD_PE_IDLE);
		break;

	default:
		pd_put_event(tcpc, &pd_event, false);
		break;
	}
}
#endif	/* CONFIG_USB_POWER_DELIVERY */

/*
static enum alarmtimer_restart
	tcpc_timer_call(struct alarm *alarm, ktime_t now)
{
	struct tcpc_timer *tcpc_timer =
		container_of(alarm, struct tcpc_timer, alarm);
	struct tcpc_device *tcpc = tcpc_timer->tcpc;

	tcpc_set_timer_tick(tcpc, tcpc_timer - tcpc->tcpc_timer);
	wake_up(&tcpc->timer_wait_que);

	atomic_dec_if_positive(&tcpc->suspend_pending);

	return ALARMTIMER_NORESTART;
}*/

/*
 * [BLOCK] Control Timer
 */

void tcpc_enable_lpm_timer(struct sgm41620_tcpc *tcpc, bool en)
{
    if (en) {
        tcpc_enable_timer(p_tcpc_dev, TYPEC_RT_TIMER_LOW_POWER_MODE);
    } else {
        tcpc_disable_timer(p_tcpc_dev, TYPEC_RT_TIMER_LOW_POWER_MODE);
    }
}

bool tcpc_is_timer_active(struct sgm41620_tcpc *tcpc, int start, int end)
{
	int i;
	bool ret = false;

	for (i = start; i < end; i++) {
		/*if (hrtimer_active(&tcpc->tcpc_timer[i].alarm.timer)) {
			ret = true;
			break;
		}*/
	}

	return ret;
}

static inline void tcpc_reset_timer_range(
		struct sgm41620_tcpc *tcpc, int start, int end)
{

	int i = 0;
	for (i = start; i < end; i++)
		multiTimerStop(&pd_timer[i]);
			
}

static void tcpc_handle_timer_triggered(MultiTimer* timer, void* userData)
{
	struct sgm41620_tcpc *tcpc = p_tcpc_dev;
//	int i = 0;
	//uint64_t tick = tcpc_get_and_clear_all_timer_tick(tcpc);
	int nr =  ((struct call_data *)(timer->userData))->id;

    if ((nr >= 0) && (nr < PD_PE_TIMER_END_ID)) {
#if TYPEC_TIMER_INFO
        printf("[%d]%s expire\n", g_sys_ticks, tcpc_timer_desc[nr].name);
#endif
        on_pe_timer_timeout(tcpc, nr);
    } else if (nr < PD_TIMER_NR) {
#if TYPEC_TIMER_INFO
        printf("[%d]%s expire\n", g_sys_ticks, tcpc_timer_desc[nr].name);
#endif
        tcpc_typec_handle_timeout(tcpc, nr);
    } else {
        // should not arrive here
    }

#if 0
	p_tcpc_dev->timer_tick = 0;
	p_tcpc_dev->timer_tick |= RT_MASK64(nr);
	
#if 1
	for (i = 0; i < PD_PE_TIMER_END_ID; i++) {
		if (p_tcpc_dev->timer_tick & RT_MASK64(i)) {
#if TYPEC_TIMER_INFO
			printf("[%d]%s expire\n", g_sys_ticks, tcpc_timer_desc[i].name);
#endif
			on_pe_timer_timeout(tcpc, i);
		}
	}
#endif /* CONFIG_USB_POWER_DELIVERY */

#if 1
	for (; i < PD_TIMER_NR; i++) {
		if (p_tcpc_dev->timer_tick & RT_MASK64(i)) {
#if TYPEC_TIMER_INFO
			printf("[%d]%s expire\n", g_sys_ticks, tcpc_timer_desc[i].name);
#endif
			tcpc_typec_handle_timeout(tcpc, i);
		}
	}
#endif
#endif
}


void tcpc_enable_timer(struct sgm41620_tcpc *tcpc, uint32_t timer_id)
{
	uint32_t r, tout;

	if (timer_id >= PD_TIMER_NR) {
		return;
	}

	uint8_t temp = 0;
#ifdef CONFIG_USB_POWER_DELIVERY
	uint8_t pd_rev = pd_get_rev(p_pd_port, temp);
#endif	/* CONFIG_USB_POWER_DELIVERY */

	
	if (timer_id >= TYPEC_TIMER_START_ID)
		tcpc_reset_timer_range(tcpc, TYPEC_TIMER_START_ID, PD_TIMER_NR);

	tout = tcpc_timer_desc[timer_id].tout;

#ifdef CONFIG_USB_POWER_DELIVERY
	if (timer_id == PD_TIMER_SENDER_RESPONSE) {
		tout = pd_rev >= PD_REV30 ?
			PD_TIMER_SENDER_RESPONSE_TIMEOUT_30 :
			PD_TIMER_SENDER_RESPONSE_TIMEOUT_20;
	}
#endif	/* CONFIG_USB_POWER_DELIVERY */

/*#if PD_DYNAMIC_SENDER_RESPONSE
	if ((timer_id == PD_TIMER_SENDER_RESPONSE) &&
		(tout > tcpc->tx_time_diff) && (tcpc->tx_time_diff > 2000)) {
		tout -= (tcpc->tx_time_diff - 2000);
		tcpc->tx_time_diff = 0;
	}
#endif*/

//#if CONFIG_USB_PD_RANDOM_FLOW_DELAY
#if 0
	if (timer_id == PD_TIMER_DFP_FLOW_DELAY ||
		timer_id == PD_TIMER_UFP_FLOW_DELAY)
		tout += TIMEOUT_VAL(jiffies & 0x07);
#endif	/* CONFIG_USB_PD_RANDOM_FLOW_DELAY */

	r =  tout / 1000;

#if TYPEC_TIMER_INFO
	printf("[%d]enable %s\n", g_sys_ticks, tcpc_timer_desc[timer_id].name);
#endif

	memset(&timer_call_data,0,sizeof(struct call_data));
	timer_call_data[timer_id].id = timer_id;
	timer_call_data[timer_id].tout = r;
#if TYPEC_TIMER_INFO
	strcpy(timer_call_data[timer_id].name, tcpc_timer_desc[timer_id].name);
#endif

	multiTimerStart(&pd_timer[timer_id], r, tcpc_handle_timer_triggered, (void*)(&timer_call_data[timer_id])); 
	/*linux ÿһ����ʱ�������Լ���timer����Ƭ������Ϊ�˽�ʡ��Դ,ѡ����timer1��
	   �����⴦���Ĺ���,�ڿ��µ�timer struct
	if(timer_id == PD_TIMER_NO_RESPONSE)
		multiTimerStart(&timer2, r, tcpc_handle_timer_triggered, (void*)(&timer_call_data)); 
	else if(timer_id == TYPEC_TIMER_ERROR_RECOVERY)
		multiTimerStart(&timer3, r, tcpc_handle_timer_triggered, (void*)(&timer_call_data)); 
	else multiTimerStart(&timer1, r, tcpc_handle_timer_triggered, (void*)(&timer_call_data));*/


}

void tcpc_disable_timer(struct sgm41620_tcpc *tcpc, uint32_t timer_id)
{
	if (timer_id >= PD_TIMER_NR) {
		return;
	}

#if TYPEC_TIMER_INFO
	printf("[%d]disable %s\n", g_sys_ticks, tcpc_timer_desc[timer_id].name);
#endif

	multiTimerStop(&pd_timer[timer_id]);
	/*to do ���Ż�
	if((timer_call_data.id == TYPEC_TIMER_ERROR_RECOVERY) || (timer_call_data.id == PD_TIMER_PS_SOURCE_OFF)){
		return;
	}
		
	//other timers to do
	if(timer_id == PD_TIMER_NO_RESPONSE)
		multiTimerStop(&timer2);
	else if(timer_id == TYPEC_TIMER_ERROR_RECOVERY)
		multiTimerStop(&timer3);
	else multiTimerStop(&timer1);*/


}

#if SG41620_C_PATCH
extern int tcpci_alert(void);
static void tcpc_handle_bist_timer_triggered(MultiTimer* timer, void* userData)
{
	int ret;
	uint32_t buf;

	ret = tcpci_get_alert_status(p_tcpc_dev, &buf);
	if (ret)
    {
        log_e("%s get alert_status fail ret =  0x%x\n",__func__,ret);
    }
	if (buf & 0x3)
		tcpci_alert();

	multiTimerStart(timer, 500, tcpc_handle_bist_timer_triggered, &bist_call_data); //restart tcpc_handle_bist_timer_triggered
}

void tcpc_enable_bist_timer(struct sgm41620_tcpc *tcpc, uint32_t timer_id)
{
	int	r =  500;
#if TYPEC_TIMER_INFO
	//log_i("Enable %s, time = %d\n", tcpc_timer_desc[timer_id].name,r);
#endif
	memset(&bist_call_data,0,sizeof(struct call_data_bist_mode));

	bist_call_data.id = timer_id;
	bist_call_data.tout = r;
	bist_call_data.enable = true;
#if TYPEC_TIMER_INFO
	strcpy(timer_call_data[timer_id].name, tcpc_timer_desc[timer_id].name);
#endif
	multiTimerStart(&bist_mode, r, tcpc_handle_bist_timer_triggered, (void*)(&bist_call_data));
}

void tcpc_disable_bist_timer(struct sgm41620_tcpc *tcpc, uint32_t timer_id)
{
	multiTimerStop(&bist_mode);
}
#endif

void tcpc_restart_timer(struct sgm41620_tcpc *tcpc, uint32_t timer_id)
{
	tcpc_disable_timer(tcpc, timer_id);
	tcpc_enable_timer(tcpc, timer_id);
}

#if 1
void tcpc_reset_pe_timer(struct sgm41620_tcpc *tcpc)
{
	//log_i("tcpc_reset_pe_timer\r\n");
	tcpc_reset_timer_range(tcpc, 0, PD_PE_TIMER_END_ID);

}
#endif /* CONFIG_USB_POWER_DELIVERY */

void tcpc_reset_typec_debounce_timer(struct sgm41620_tcpc *tcpc)
{
	//log_i("tcpc_reset_typec_debounce_timer\r\n");
	tcpc_reset_timer_range(tcpc, TYPEC_TIMER_START_ID, PD_TIMER_NR);

}

void tcpc_reset_typec_try_timer(struct sgm41620_tcpc *tcpc)
{

	tcpc_reset_timer_range(tcpc,
			TYPEC_TRY_TIMER_START_ID, TYPEC_TIMER_START_ID);

}


int tcpci_timer_init(struct sgm41620_tcpc *tcpc)
{
	multiTimerInstall(getPlatformTicks);
	log_i("PD Timer number = %d\n", PD_TIMER_NR);

//	tcpc->timer_tick = 0;

	log_i("%s : init OK\n", __func__);
	return 0;
}

int tcpci_timer_deinit(struct sgm41620_tcpc *tcpc)
{

	tcpc_reset_timer_range(tcpc, 0, PD_TIMER_NR);

	log_i("%s : de init OK\n", __func__);
	return 0;
}
